Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some JSDoc comments to rustdoc JS #92026

Merged
merged 1 commit into from
Dec 23, 2021
Merged

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Dec 17, 2021

This follows the Closure Compiler dialect of JSDoc, so we can use it to do some basic type checking. We don't plan to compile with Closure Compiler, just use it to check types. See https://github.com/google/closure-compiler/wiki/ for details.

To try checking the annotations, run:

npm i -g google-closure-compiler
google-closure-compiler -W VERBOSE build/x86_64-unknown-linux-gnu/doc/{search-index1.59.0.js,crates1.59.0.js} src/librustdoc/html/static/js/{search.js,main.js,storage.js} --externs src/librustdoc/html/static/js/externs.js >/dev/null

You'll see some warnings that "String continuations are not recommended". I'm not addressing those right now.

Discussed on Zulip.

r? @GuillaumeGomez

@jsha jsha added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) labels Dec 17, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 17, 2021
@rust-log-analyzer

This comment has been minimized.


/**
* @typedef {{
* doc: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how useful this comment is...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main goal for this comment is to describe the schema of these input rows from search-index.js, in a way that can be automatically checked by Closure Compiler.

I went ahead and wrote a longer comment trying to describe the schema better. I had to put "is a mystery" for some of the fields because I couldn't figure them out. Maybe you can help me fill in the details. :-)

@GuillaumeGomez
Copy link
Member

The adds of the comment looks good overall. My issue is about the newly created global variables: we tried to avoid that as much as possible originally because it's super easy in JS to overwrite them without taking care in a sub-function...

@jyn514
Copy link
Member

jyn514 commented Dec 17, 2021

To try checking the annotations, run:

Can you document this somewhere other than the PR description, please? Maybe the dev-guide or at the top of one of the KS files?

@jsha
Copy link
Contributor Author

jsha commented Dec 17, 2021

the newly created global variables

Yeah, these are a bit odd- but that is how Closure Compiler does typedefs. Essentially you define a dummy variable that doesn't do anything, just to attach the type information to it.

We're not really at risk of overwriting these (CrateCorpus, Corpus, ParsedQuery, Row), because we don't actually rely on their values anywhere. They're purely a place to attach type information.

Can you document this somewhere other than the PR description, please? Maybe the dev-guide or at the top of one of the KS files?

I put it in a README in the JS directory.

@GuillaumeGomez
Copy link
Member

Yeah, these are a bit odd- but that is how Closure Compiler does typedefs. Essentially you define a dummy variable that doesn't do anything, just to attach the type information to it.

It seems very wrong to me: we're adding more (unnecessary) code to satisfy the doc generator... Not only that but you need to create a file externs.js to only satisfy this tool. This is problematic in my opinion.

We're not really at risk of overwriting these (CrateCorpus, Corpus, ParsedQuery, Row), because we don't actually rely on their values anywhere. They're purely a place to attach type information.

I don't think this is the right place to put this documentation. What about putting it on the function generating the search index? It's where I would look if I wanted to know what the argument is doing. And that would also allow to getting rid of these newly added variables.

I put it in a README in the JS directory.

👍

@jsha
Copy link
Contributor Author

jsha commented Dec 18, 2021

we're adding more (unnecessary) code to satisfy the doc generator

In this case we're not using it as a doc generator but a type checker. I did realize I can move these typedefs into externs.js, where they won't generate a var Foo in the minified output.

Can you explain why you think externs.js is bad? It is not built into rustdoc and it doesn't wind up in the minified output.

What about putting it on the function generating the search index?

Moved to buildIndex().

Cargo.lock Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member

Can you explain why you think externs.js is bad? It is not built into rustdoc and it doesn't wind up in the minified output.

It was because it only contained two lines which didn't seem to have any link to the rest. So for potential new contributors, very confusing. Could you add a comment at the top of the file explaining why it exists please?

This follows the Closure Compiler dialect of JSDoc, so we
can use it to do some basic type checking. We don't plan to
compile with Closure Compiler, just use it to check types. See
https://github.com/google/closure-compiler/wiki/ for details.
@jsha
Copy link
Contributor Author

jsha commented Dec 22, 2021

Nit fixed!

@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Dec 22, 2021

📌 Commit 7ba086c has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 22, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#88858 (Allow reverse iteration of lowercase'd/uppercase'd chars)
 - rust-lang#91544 (Fix duplicate derive clone suggestion)
 - rust-lang#92026 (Add some JSDoc comments to rustdoc JS)
 - rust-lang#92117 (kmc-solid: Add `std::sys::solid::fs::File::read_buf`)
 - rust-lang#92139 (Change Backtrace::enabled atomic from SeqCst to Relaxed)
 - rust-lang#92146 (Don't emit shared files when scraping examples from dependencies in Rustdoc)
 - rust-lang#92208 (Quote bat script command line)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9f68b6e into rust-lang:master Dec 23, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: rustdoc UI (generated HTML) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants